package com.mjlf.jol;

import org.openjdk.jol.info.ClassLayout;

/**
 * @ClassName JolTest1
 * @auther mjlf
 * @Date 2019/7/16 9:38
 * @Description 重量级锁
 */
public class JolTest9 {
    public static A a;

    public static void main(String[] args) throws InterruptedException {
        a = new A();
        System.out.println("before lock");
        System.out.println(ClassLayout.parseInstance(a).toPrintable());

        Thread t1 = new Thread(){

            @Override
            public void run(){
                synchronized (a){
                    System.out.println("before1 lock");
                    System.out.println(ClassLayout.parseInstance(a).toPrintable());
                }
            }
        };
        t1.start();
        t1.join();

        synchronized (a){
            System.out.println("线程竞争，升级为重量级锁");
            System.out.println(ClassLayout.parseInstance(a).toPrintable());
        }
    }
}
